package com.ruoyi.lvlian.service.impl;

import java.util.List;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.MD5Utils;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.lvlian.vo.CameraVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.lvlian.mapper.CameraMapper;
import com.ruoyi.lvlian.domain.Camera;
import com.ruoyi.lvlian.service.ICameraService;

/**
 * 摄像头Service业务层处理
 *
 * @author lvlian
 * @date 2025-04-24
 */
@Service
public class CameraServiceImpl implements ICameraService {
    @Autowired
    private CameraMapper cameraMapper;

    /**
     * 查询摄像头
     *
     * @param id 摄像头主键
     * @return 摄像头
     */
    @Override
    public Camera selectCameraById(String id) {
        return cameraMapper.selectCameraById(id);
    }

    /**
     * 查询摄像头列表
     *
     * @param camera 摄像头
     * @return 摄像头
     */
    @Override
    public List<Camera> selectCameraList(Camera camera) {
        return cameraMapper.selectCameraList(camera);
    }

    /**
     * 新增摄像头
     *
     * @param camera 摄像头
     * @return 结果
     */
    @Override
    public int insertCamera(Camera camera) {
        camera.setId(    MD5Utils.md5( camera.getName()  ) );
        camera.setCreateUser(SecurityUtils.getUsername());
        camera.setCreateDate(DateUtils.getCurrentTime());
        return cameraMapper.insertCamera(camera);
    }

    /**
     * 修改摄像头
     *
     * @param camera 摄像头
     * @return 结果
     */
    @Override
    public int updateCamera(Camera camera) {
        int updateResult =       cameraMapper.updateCamera(camera);
        if (0 == updateResult) {
            updateResult = insertCamera(camera);
        }
        return updateResult;

    }

    /**
     * 批量删除摄像头
     *
     * @param ids 需要删除的摄像头主键
     * @return 结果
     */
    @Override
    public int deleteCameraByIds(String[] ids) {
        return cameraMapper.deleteCameraByIds(ids);
    }

    /**
     * 删除摄像头信息
     *
     * @param id 摄像头主键
     * @return 结果
     */
    @Override
    public int deleteCameraById(String id) {
        return cameraMapper.deleteCameraById(id);
    }

    @Override
    public List<CameraVo> queryCameraList(List<String> orgCodes ) {
        return cameraMapper.queryCameraList(orgCodes);
    }
}
